package com.huawei.hwclouds.lubanops.demo.product.client;

import com.huawei.hwclouds.lubanops.demo.common.client.HttpCallResult;
import com.huawei.hwclouds.lubanops.demo.common.client.HttpClient;
import com.huawei.hwclouds.lubanops.demo.common.client.LubanopsClientBase;
import com.huawei.hwclouds.lubanops.demo.common.model.HttpHeaderMap;
import com.huawei.hwclouds.lubanops.demo.common.util.ConfigServiceUtil;
import com.huawei.hwclouds.lubanops.demo.product.client.entity.GetProductDetailResult;

/**
 * APM MASTER 相关的服务
 */
public class ProductServiceClient extends LubanopsClientBase {

    private static final String CONFIG_SERVER_ADDRESS = ConfigServiceUtil.getConfigServerAddress(
        "product-service-client.properties", ProductHeaderFactory.class);

    private static final HttpClient CLIENT = ConfigServiceUtil.getHttpClient(
        "product-service-client.properties", ProductHeaderFactory.class);

    private static final String API_ADDRESS_PREFIX = "/apm2/demo/product/";



    private ProductServiceClient() {
    }

    /**
     * 此方法用于初始化这个类，读取配置文件，判断合法性 <br>
     *
     * @author y00438022
     * @since 2020年3月24日
     */
    public static void init() {

    }

    /**
     * 获取系统所有的aksk信息，用于注册和心跳 <br>
     *
     * @author l00471413
     * @since 2020年04月03日
     */
    public static GetProductDetailResult getProductDetail(int productId) {
        String url = CONFIG_SERVER_ADDRESS + API_ADDRESS_PREFIX + "v1/getProductDetail?productId=" + productId;
        HttpCallResult httpResult = CLIENT.sendGet(url, null, HttpHeaderMap.getDefaultHeader());
        return populateResult(httpResult, GetProductDetailResult.class);
    }

    public static void reduceRepertory(String param) {
        String url = CONFIG_SERVER_ADDRESS + API_ADDRESS_PREFIX + "v1/reduce/repertory";
        CLIENT.sendPostJSON(url, HttpHeaderMap.getDefaultHeader(), param);
    }

    public static void queryProductInfo(String page) {
        String url = CONFIG_SERVER_ADDRESS + API_ADDRESS_PREFIX + "v1/query/info";
        CLIENT.sendPostJSON(url, HttpHeaderMap.getDefaultHeader(), page);
    }
}
